package system;

import Main.Parameters;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Console input reader
 * After successfull read of a line system transfers it to libary wich currently waiting for console input
 * @author ZeM
 */
public class UserInputStream implements Runnable {

    public BufferedReader input;

    public void run() {
        input = new BufferedReader(new InputStreamReader(System.in));
        do{
        try {
            String line = input.readLine();
             if (line != null && line.length() > 0) {
                    //checking if QuitTimer is working
                    if (Parameters.ExitTimerIsWorking) {
                        ExitTimer.stop = true; //stop timer
                        Parameters.QuitTime = -1; //quit only by user command

                    }
           Input(line);
             }
        } catch (IOException ex) {

        }
        }while (!Parameters.exit);

    }

     /**
     * Input to currently active library
     * @param line - String to input
     */
    public void Input(String line){
        if(Parameters.LibConsoleInputReceiver!=-1){
                Parameters.Libs[Parameters.LibConsoleInputReceiver].Input(line);
            }
    }

}
